package com.xiyoo.cw.controller;


import com.xiyoo.cw.common.Result;
import com.xiyoo.cw.common.enums.ResultCode;
import com.xiyoo.cw.domain.User;
import com.xiyoo.cw.domain.user.UserRequest;
import com.xiyoo.cw.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Objects;

/**
 * @Description:
 * @Date: 2025/5/13 10:33
 * @Author: zhouzhongqing
 */

@RestController
@RequestMapping("/api/user")
@Api(tags = "用户相关")
@Slf4j
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "获取验证码", notes = "获取验证码")
    @PostMapping("captcha")
    public Result<Object> getCaptcha(@RequestBody @Valid User user) {
        if (Objects.isNull(user)) {
            return new Result<>(ResultCode.ERROR, "参数错误");
        }
        return userService.getCaptcha(user);
    }

    @ApiOperation(value = "登录", notes = "登录")
    @PostMapping("login")
    public Result<Object> login(@RequestBody @Valid UserRequest request) {
        if (Objects.isNull(request)) {
            return new Result<>(ResultCode.ERROR, "参数错误");
        }
        return userService.login(request);
    }




}

